1 #define MAX(a,b) ((a>b)?(a):(b))
4 int lcs(const string
&s
, const string
&t
){
5 int m
= s
.size(), n
= t
.size();
6 if (m
== 0 || n
== 0) return 0;
7 for (int i
=0; i
<=m
; ++i
)
9 for (int j
=1; j
<=n
; ++j
)
11 for (int i
=0; i
<m
; ++i
)
12 for (int j
=0; j
<n
; ++j
)
14 dp
[i
+1][j
+1] = dp
[i
][j
]+1;
16 dp
[i
+1][j
+1] = MAX(dp
[i
+1][j
], dp
[i
][j
+1]);